package com.csii.branch;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.csii.branch.mapper.*;
import com.csii.branch.mapper.entity.*;
import com.csii.branch.service.ICdBranchBaseInfoService;
import com.csii.branch.service.ICdBranchStatDeviceService;
import com.csii.branch.service.ICdBranchStatUserService;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.checkerframework.checker.units.qual.A;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;

/**
 * @Description TODO
 * @Date 2020/12/22 18:54
 * @Created by Ian
 * @Contact: 19107614@qq.com
 */
@SpringBootTest(classes = WebApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@RunWith(SpringRunner.class)
@Slf4j
public class BranchStatMock {
    @Autowired
    private CdBranchStatUserMapper branchStatUserMapper;
    @Autowired
    private ICdBranchBaseInfoService cdBranchBaseInfoService;
    @Autowired
    private CdBranchStatDeviceMapper cdBranchStatDeviceMapper;
    @Autowired
    private CdBranchStatDailyMapper branchStatDailyMapper;
    @Autowired
    private CdBranchStatDepositMapper branchStatDepositMapper;
    @Autowired
    private CdBranchStatLoanMapper branchStatLoanMapper;
    @Autowired
    private CdBranchSupervisorInfoMapper branchSupervisorInfoMapper;
    @Autowired
    private CdBranchPlaceInfoMapper cdBranchPlaceInfoMapper;
    @Autowired
    private CdBranchAroundInfoMapper cdBranchAroundInfoMapper;
    @Autowired
    private CdBranchLicenseInfoMapper cdBranchLicenseInfoMapper;
    @Autowired
    private CdBranchDeviceInfoMapper cdBranchDeviceInfoMapper;
    @Test
    public void testBranchUser(){
        Date date=new Date();
        for(CdBranchBaseInfo info:cdBranchBaseInfoService.list()) {
            for (int i = 0; i < 90; i++) {

                for (int j = 1; j < 5; j++) {

                    for (int k = 1; k < 6; k++) {
                        CdBranchStatUser user = new CdBranchStatUser();
                        user.setStatDate(DateUtil.offsetDay(date, -i));
                        user.setSource(j + "");
                        user.setCustomerType(k + "");
                        user.setNetId(info.getId());
                        user.setNums(RandomUtil.randomInt(1000,1500));
                        branchStatUserMapper.insert(user);
                        log.info(" add data {}",user);
                    }
                }
            }
        }
    }
    @Test
    public void testBranchDeviceStat(){
        Map<String, List<String>> hashMap =new HashMap<>();
        hashMap.put("1", Lists.list("ATM机","自动存取款一体机","点钞机","零币机"));
        hashMap.put("2", Lists.list("智能高柜","自助高柜"));
        hashMap.put("3", Lists.list("消防栓","灭火器"));
        hashMap.put("4", Lists.list("传真机","办公桌","电脑","电话"));
        for(CdBranchBaseInfo info:cdBranchBaseInfoService.list()) {
            hashMap.forEach((k,v)->{
                v.forEach(s->{
                    CdBranchStatDevice device=new CdBranchStatDevice();
                    device.setNetId(info.getId());
                    device.setFaultRate(RandomUtil.randomInt(1,4)+"");
                    device.setUseLevel(RandomUtil.randomInt(1,4)+"");
                    device.setUseRate(RandomUtil.randomInt(10,80));
                    device.setAmount(RandomUtil.randomInt( 30,200));
                    device.setType(k);
                    device.setName(s);
                    cdBranchStatDeviceMapper.insert(device);
                });
            });
        }
    }
    @Test
    public void testDailyService(){
        Date date=new Date();
        for(CdBranchBaseInfo info:cdBranchBaseInfoService.list()) {
            for (int i = 0; i < 90; i++) {
                CdBranchStatDaily daily = new CdBranchStatDaily();
                daily.setNetId(info.getId());
                daily.setStatDate(DateUtil.offsetDay(date, -i));
                daily.setCpxse(RandomUtil.randomBigDecimal(BigDecimal.valueOf(2000000),BigDecimal.valueOf(50000000)));
                daily.setCreditCardAdd(RandomUtil.randomBigDecimal(BigDecimal.valueOf(1000),BigDecimal.valueOf(5000)));
                daily.setCreditCardSum(BigDecimal.valueOf(100000000));
                daily.setCustAdd(RandomUtil.randomInt(3000,7000));
                daily.setDepositAdd(RandomUtil.randomBigDecimal(BigDecimal.valueOf(2000000),BigDecimal.valueOf(50000000)));
                daily.setLcxse(RandomUtil.randomBigDecimal(BigDecimal.valueOf(3000000),BigDecimal.valueOf(80000000)));
                daily.setLdRate(RandomUtil.randomInt(10,20));
                daily.setYbtxse(RandomUtil.randomBigDecimal(BigDecimal.valueOf(2000000),BigDecimal.valueOf(5000000)));
                daily.setZjywsr(RandomUtil.randomBigDecimal(BigDecimal.valueOf(2000000),BigDecimal.valueOf(5000000)));
                daily.setZcfzRate(RandomUtil.randomInt(30,200));
                daily.setYyzc(RandomUtil.randomBigDecimal(BigDecimal.valueOf(200000),BigDecimal.valueOf(800000)));
                daily.setBldk(RandomUtil.randomBigDecimal(BigDecimal.valueOf(2000000),BigDecimal.valueOf(50000000)));
                branchStatDailyMapper.insert(daily);
            }
        }
    }
    @Test
    public void testDepositService(){
        Date date=new Date();
        for(CdBranchBaseInfo info:cdBranchBaseInfoService.list()) {
            for (int i = 0; i < 90; i++) {
                CdBranchStatDeposit deposit=new CdBranchStatDeposit();
                deposit.setAmount(BigDecimal.valueOf(8000000000l));
                deposit.setNetId(info.getId());
                deposit.setType(RandomUtil.randomInt(1,6)+"");
                deposit.setNewAdd(RandomUtil.randomBigDecimal(BigDecimal.valueOf(20000000),BigDecimal.valueOf(500000000)));
                deposit.setStatDate(DateUtil.offsetDay(date, -i));
                branchStatDepositMapper.insert(deposit);
            }
        }

    }
    @Test
    public void testSupervisorService(){
        for(CdBranchBaseInfo info:cdBranchBaseInfoService.list()) {
            CdBranchSupervisorInfo supervisorInfo=new CdBranchSupervisorInfo();
            supervisorInfo.setAmount(RandomUtil.randomInt(300,1000)+"万");
            supervisorInfo.setNetId(info.getId());
            supervisorInfo.setCashPlace(RandomUtil.randomBoolean()?"是":"否");
            supervisorInfo.setDmArea(RandomUtil.randomInt(500,5000)+"平米");
            supervisorInfo.setDtArea(RandomUtil.randomInt(200,300)+"平米");
            supervisorInfo.setDzPlace(RandomUtil.randomBoolean()?"是":"否");
            supervisorInfo.setFixCom("百安居装修公司");
            supervisorInfo.setXfDesc("无隐患");
            supervisorInfo.setStyle("商业");
            supervisorInfo.setSupervisorCom("中建五局");
            supervisorInfo.setQmArea(RandomUtil.randomInt(2000,3000)+"平米");
            supervisorInfo.setManagePlace(RandomUtil.randomBoolean()?"是":"否");
            supervisorInfo.setNonCashPlace(RandomUtil.randomBoolean()?"是":"否");
            supervisorInfo.setOfficePlace("是");
            supervisorInfo.setMcArea(RandomUtil.randomInt(200,300)+"平米");
            supervisorInfo.setNetName(info.getName());
            supervisorInfo.setGbPlace(RandomUtil.randomBoolean()?"是":"否");
            //branchSupervisorInfoMapper.insert(supervisorInfo);
            CdBranchPlaceInfo placeInfo=new CdBranchPlaceInfo();
            placeInfo.setAddress("");
            placeInfo.setArea(RandomUtil.randomInt(500,5000)+"平米");
            placeInfo.setCq("南方科技责任有限公司");
            placeInfo.setFee("10w");
            placeInfo.setFloor(RandomUtil.randomInt(1,30)+"");
            placeInfo.setNetId(info.getId());
            placeInfo.setNetName(info.getName());
            placeInfo.setWyLevel("A级");
            placeInfo.setWyName("科技园物业");
            placeInfo.setPlaceIn("1");
            placeInfo.setPlaceUse("商业营业");
           // cdBranchPlaceInfoMapper.insert(placeInfo);
            CdBranchDeviceInfo cdBranchDeviceInfo=new CdBranchDeviceInfo();
            cdBranchDeviceInfo.setNetId(info.getId());
            cdBranchDeviceInfo.setNetName(info.getName());
            cdBranchDeviceInfo.setDeviceNo(RandomUtil.randomStringUpper(12));
            cdBranchDeviceInfo.setDeviceName("ATM机");
            cdBranchDeviceInfo.setDeviceType("现金设备");
           // cdBranchDeviceInfoMapper.insert(cdBranchDeviceInfo);
            CdBranchAroundInfo aroundInfo=new CdBranchAroundInfo();
            aroundInfo.setBus1Name("车站01");
            aroundInfo.setBus2Name("车站02");
            aroundInfo.setBus3Name("车站03");
            aroundInfo.setHspNums(RandomUtil.randomInt(0,10));
            aroundInfo.setJdName("桃园街道");
            aroundInfo.setJdNums(RandomUtil.randomInt(1,4));
            aroundInfo.setWdNum(RandomUtil.randomInt(5,30));
            aroundInfo.setZhwdNums("100w");
            aroundInfo.setZgNums(RandomUtil.randomInt(5,10));
            aroundInfo.setXxNums(RandomUtil.randomInt(1,10));
            aroundInfo.setNetType("金融");
            aroundInfo.setSjNums(RandomUtil.randomInt(20,300));
            aroundInfo.setSq1Name("前海明珠");
            aroundInfo.setSq2Name("夜明珠");
            aroundInfo.setSq3Name("明珠苑");
            aroundInfo.setNetId(info.getId());
            aroundInfo.setNetName(info.getName());
            cdBranchAroundInfoMapper.insert(aroundInfo);
        }
    }
    @Test
    public void testLoanService(){
        Date date=new Date();
        for(CdBranchBaseInfo info:cdBranchBaseInfoService.list()) {
            for (int i = 0; i < 90; i++) {
                CdBranchStatLoan loan=new CdBranchStatLoan();
                loan.setAmount(BigDecimal.valueOf(8000000000l));
                loan.setNetId(info.getId());
                loan.setType(RandomUtil.randomInt(1,6)+"");
                loan.setNewAdd(RandomUtil.randomBigDecimal(BigDecimal.valueOf(20000000),BigDecimal.valueOf(500000000)));
                loan.setStatDate(DateUtil.offsetDay(date, -i));
                branchStatLoanMapper.insert(loan);
            }
        }

    }
    public static void testNum(int a){
        int a1=a/10000;
        int a2=a%10000/1000;
        int a4=a%100/10;
        int a5=a%10;
        if((a1==a5)&&(a2==a4))
            System.out.println(a+":true");
        else
            System.out.println(a+":false");
    }
    public static void main(String[] args) {
        int[] a={12312,23413,23532};
        for (int c:
             a) {
            testNum(c);
        }
        String[] names={"zhang","wang","i"};
        String x="D:/root/branch/generatecode\\src\\main\\java\\a\\controller\\DemoUserInfoController.java";
        System.out.println(x.indexOf("\\src\\main\\java\\"));
        System.out.println(x.indexOf("src/main/java"));

        //密码加密
        StandardPBEStringEncryptor encryptot = new StandardPBEStringEncryptor();
        encryptot.setPassword("branch2021");
        String ps =  encryptot.encrypt("root1234");
        String p =  encryptot.encrypt("123456");
        String xx =  encryptot.encrypt("1414141414");
        System.out.println(ps);
        System.out.println(p);
        System.out.println(x);
        System.out.println(encryptot.decrypt(ps));
        System.out.println(encryptot.decrypt(p));
        System.out.println(encryptot.decrypt(xx));
    }



}
